﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Settings.aspx.cs" Inherits="WF.Web.Pages.HR.Settings" %>

<%@ Register Assembly="WF.Web" Namespace="WF.Web.Controls" TagPrefix="cc1" %>
<%@ Register Src="~/Pages/UserControl/UCPager.ascx" TagName="UCPager" TagPrefix="uc1" %>
<%@ Register Src="~/Pages/UserControl/ToolBar.ascx" TagName="ToolBar" TagPrefix="uc2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../css/main.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>

    <style type="text/css">
        html { font-size: 9pt; }
        #tvDept table { width: auto; }
        .dvTitle { margin: 0 0 0 0; }
        .inputQuery { width: 350px; height: 25px; padding: 0 0 0 15px; }
        .inputNoStyle { border: none; height: 30px; width: 450px; font-family: Georgia; font-size: 14pt; }
        #container { width: 100%; height: 800px; overflow: auto; }
        .dataGridExpand { float: left; }
        .settings_left_content { height: 400px; overflow-y: scroll; text-align: center; padding: 15px; }
        .settings_right_content { height: 400px; overflow-y: scroll; padding: 15px; }
        .settings_userlist { margin: 15px 0 0 0; }
        .settings_bottom_content { height: 40px; }
        .dvContent { position: relative; }
        .dvCover { height: 430px; width: 100%; z-index: 999; background-color: lightgray; position: absolute; opacity: 0.5; }
        .imgLoading { left: 275px; top: 202.5px; position: absolute; }
        .dvMain { width: 1120px; }
        .dvPwd { margin: 10px; }
    </style>
    <script type="text/javascript">

        $(function () {
            //加载排除人员
            loadExcluder();

            //加载通用码
            getCommonCode();

            //事件

            $("#tvDept input:checkbox").click(setTreeDept);

            $("#btnQuery").click(queryUsers);

            $("[name='chkSelect']").live("click", setUserList);

            $(".inputNoStyle").keyup(setCommonCode);
        });

        //部门权限设定
        function setTreeDept() {
            var deptArr = "";
            $("#tvDept input:checkbox").each(function (i, obj) {
                if ($(obj).attr("checked")) {
                    deptArr += $(obj).next().text() + ";";
                }
            });
            $.post("../../AshxHandler/HandlerDeptLimit.ashx", { deptName: deptArr }, function (res) { });
        }

        //加载排除人员
        function loadExcluder() {
            doAsyncForEmployees({
                data: { args: "load" },
                isRebind: true
            });
        }

        //搜索
        function queryUsers() {
            if ($.trim($("#txtQuery").val()) != "") {
                doAsyncForEmployees({
                    data: { args: "query", conds: $("#txtQuery").val() },
                    isRebind: true
                });
            }
            else
                loadExcluder();
        }

        //激活或取消人员列外
        function setUserList() {
            var obj = $(this);
            var ckFlag = obj.attr("checked");
            var code = obj.parents("tr:first").find("td:eq(2)").text();
            if (code != "") {
                doAsyncForEmployees({ data: { args: "set", code: code, flag: ckFlag } }, obj);
            }
        }

        //获取通用码
        function getCommonCode() {
            doAsyncForCode({
                args: "get"
            });
        }

        //修改通用码
        function setCommonCode(auto) {
            doAsyncForCode({
                args: "set",
                auto: typeof(auto) == "object" ? false : true,
                code: $(this).val()
            });
        }

        //一行接着一行绑定 人员列表数据绑定
        function dataBindLineByLine(data, isRebind) {
            if (isRebind) $(".genTr").remove();
            data = eval(data);
            if (data != undefined && data != "" && data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    var row = "";
                    row += "<tr class='genTr'>";
                    row += "<td>";
                    row += "<input type='checkbox' " + (data[i].Status == "已开通" ? "checked='checked'" : "") + " name='chkSelect' />";
                    row += "</td>"
                    row += "<td>" + data[i].Name + "</td>";
                    row += "<td>" + data[i].Code + "</td>";
                    row += "<td>" + data[i].DomainName + "</td>";
                    row += "<td style='color:" + (data[i].Status == "已开通" ? "green" : "red") + "'>" + data[i].Status + "</td>";
                    row += "</tr>";
                    $("#tbEmp").append(row);
                }
            }
            else {
                row += "<tr class='genTr'><td colspan='5'>没有数据</td></tr>";
                $("#tbEmp").append(row);
            }
        }

        //人员列表异步处理方法
        function doAsyncForEmployees(obj, objCk) {
            $.ajax({
                cache: false,
                url: "../../AshxHandler/HandlerEmpLimit.ashx",
                data: obj.data,
                beforeSend: function () {
                    $(".dvCover").show();
                },
                success: function (data) {
                    if (obj.data.args != undefined && obj.data.args == "set")
                        objCk.parents("tr:first").find("td:eq(4)").css("color", (obj.data.flag ? "green" : "red")).html(obj.data.flag ? "已开通" : "未开通");
                    else
                        dataBindLineByLine(data, obj.isRebind);
                },
                complete: function () {
                    $(".dvCover").hide();
                }
            });
        }

        //通用登录码异步处理方法
        function doAsyncForCode(data) {
            $.post("../../AshxHandler/HandlerCommonCode.ashx", data, function (res) {
                $(".inputNoStyle").val(res);
            });
        }

    </script>
</head>
<body>
    <form id="form1" runat="server" accesskey="">
        <div id="container">
            <div class="dvMain">

                <div class="dataGrid dataGridExpand" style="width: 575px;">
                    <div class="ititle">
                        <h4 title="">人员排除</h4>
                    </div>
                    <div class="dvContent">
                        <div class="dvCover">
                            <img class="imgLoading" src="../../images/loading2.GIF" />
                        </div>
                        <div class="settings_left_content">
                            <div class="dvTitle">
                                <asp:TextBox CssClass="inputs inputQuery" placeholder="姓名 工号 账号" runat="server" ID="txtQuery"></asp:TextBox>

                                <input tabindex="0" type="button" class="inputbtn" value="搜索" id="btnQuery" />

                                <div class="settings_userlist">
                                    <div class="dataGrid">
                                        <table id="tbEmp" cellspacing="0" class="Grid">
                                            <tr>
                                                <th></th>
                                                <th>姓名</th>
                                                <th>工号</th>
                                                <th>账号</th>
                                                <th></th>
                                            </tr>

                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="dataGrid dataGridExpand" style="width: 45%; margin: 0 0 0 10px;">
                    <div class="ititle">
                        <h4>开机打卡例外部门</h4>
                    </div>
                    <div class="settings_right_content">
                        <div class="dvTitle">
                            <asp:TextBox CssClass="inputs inputQuery" placeholder="部门名称 部门代码" runat="server" ID="TextBox1"></asp:TextBox>
                            <input tabindex="0" type="button" class="inputbtn" value="搜索" id="Button1" />
                        </div>
                    </div>
                </div>

                <div class="dataGrid dataGridExpand" style="width: 575px;">
                    <div class="ititle">
                        <h4>通用登录码</h4>
                    </div>
                    <div class="settings_bottom_content">
                        <div class="dvPwd">
                            <input type='text' class='inputNoStyle' />
                            <a href="#" onclick="setCommonCode(0);">随机生成代码</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>
</html>
